package com.ziyun.erp.web.modules.goodsCraftPrice.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.ziyun.erp.modules.goods.entity.GoodsAttributeEntity;
import com.ziyun.erp.modules.goods.service.GoodsAttributeService;
import com.ziyun.erp.modules.goods.service.GoodsOptionService;
import com.ziyun.erp.modules.goodsCraftPrice.dto.GoodsCraftPriceDto;
import com.ziyun.erp.modules.goodsCraftPrice.entity.GoodsCraftPriceEntity;
import com.ziyun.erp.modules.goodsCraftPrice.service.GoodsCraftPriceService;
import com.ziyun.erp.modules.quoteAttribute.entity.QuoteAttributeEntity;
import com.ziyun.erp.modules.quoteAttribute.service.QuoteAttributeService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 报价工艺价格表
 *
 * @author zh
 * @email 296588519@qq.com
 * @date 2018-09-10 10:43:12
 */
@RestController
@RequestMapping("goodsCraftPrice/quoteGoodsCraftPrice")
public class QuoteGoodsCraftPriceController {
    @Autowired
    private GoodsCraftPriceService goodsCraftPriceService;

    @Autowired
    private QuoteAttributeService quoteAttributeService;

    /**
     * 获取报价商品工艺
     */
    @RequestMapping("/getQuoteGoodsCraftList")
    @RequiresPermissions("goodsCraftPrice:goodscraftprice:info")
    public R getQuoteGoodsCraftList(String attributeOrigin){

        List<Map<String,Object>> goodsCraftList =   quoteAttributeService.getQuoteGoodsCraftList(attributeOrigin);

        return R.ok().put("goodsCraftList", goodsCraftList);
    }


    /**
     * 获取印刷报价商品工艺价格
     */
    @RequestMapping("/getYinhuaGosodsCraftPriceList")
    @RequiresPermissions("goodsCraftPrice:goodscraftprice:info")
    public R getGoodsCraftPriceList(){
        //商户id 此处自营写死
        Long sellerId = 1L;

        Map<String ,Object> yinshuaGoodsCraftPriceData = goodsCraftPriceService.getYinshuaGoodsCraftPriceList(sellerId);

        return R.ok().put("yinshuaGoodsCraftPriceData", yinshuaGoodsCraftPriceData);
    }

    /**
     * 获取印刷商品工艺选项
     */
    @RequestMapping("/getYinshuaGoodsCraftOptionList")
    @RequiresPermissions("goodsCraftPrice:goodscraftprice:info")
    public R getYinshuaGoodsCraftOptionList(Integer attributeId){
        //商户id 此处自营写死
        Long sellerId = 1L;

        Map<String,Object> parasMap = new HashMap<>();
        parasMap.put("sellerId", sellerId);
        parasMap.put("attributeId", attributeId);
        parasMap.put("printType", "shangwuyinshua");
        List<GoodsCraftPriceEntity> yinshuaGoodsCraftOptionPriceList = goodsCraftPriceService.getQuoteGoodsCraftOptionPriceList(parasMap);


        return R.ok().put("yinshuaGoodsCraftOptionPriceList", yinshuaGoodsCraftOptionPriceList);
    }


    /**
     * 保存印刷商品工艺价格
     */
    @RequestMapping("/saveYinshua")
    @RequiresPermissions("goodsCraftPrice:goodscraftprice:save")
    public R saveYinshua(@Valid @RequestBody GoodsCraftPriceDto goodsCraftPriceDto){
        // 获取当前登录人
        String userName = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
        //商户id 此处自营写死
        Long sellerId = 1L;
        goodsCraftPriceService.saveYinshua(goodsCraftPriceDto.getCraftPriceList(), userName, sellerId);
        return R.ok();
    }

    /**
     * 根据工艺配价Ids删除
     */
    @RequestMapping("/deleteByIds")
    @RequiresPermissions("goodsCraftPrice:goodscraftprice:delete")
    public R deleteByIds(@RequestBody List<Integer> ids){
        goodsCraftPriceService.deleteByIds(ids);
        return R.ok();
    }

    /**
     * 根据工艺删除
     */
    @RequestMapping("/deleteByAttributeId")
    @RequiresPermissions("goodsCraftPrice:goodscraftprice:delete")
    public R deleteByAttributeId(Integer attributeId){
        //商户id 此处自营写死
        Long sellerId = 1L;

        Map<String, Object> parasMap = new HashMap<>();
        parasMap.put("attributeId", attributeId);
        parasMap.put("sellerId", sellerId);

        goodsCraftPriceService.deleteQuoteByAttributeId(parasMap);
        return R.ok();
    }


    /*============ 以下为快印商品工艺价格相关信息 ====================*/

    /**
     * 获取快印报价商品工艺价格
     */
    @RequestMapping("/getKuaiyinGosodsCraftPriceList")
    @RequiresPermissions("goodsCraftPrice:goodscraftprice:info")
    public R getKuaiyinGosodsCraftPriceList(){
        //商户id 此处自营写死
        Long sellerId = 1L;

        Map<String ,Object> kuaiyinGoodsCraftPriceData = goodsCraftPriceService.getKuaiyinGoodsCraftPriceList(sellerId);

        return R.ok().put("kuaiyinGoodsCraftPriceData", kuaiyinGoodsCraftPriceData);
    }


    /**
     * 获取快印商品工艺选项
     */
    @RequestMapping("/getKuaiyinGoodsCraftOptionList")
    @RequiresPermissions("goodsCraftPrice:goodscraftprice:info")
    public R getKuaiyinGoodsCraftOptionList(Integer attributeId){
        //商户id 此处自营写死
        Long sellerId = 1L;

        Map<String,Object> parasMap = new HashMap<>();
        parasMap.put("sellerId", sellerId);
        parasMap.put("attributeId", attributeId);
        parasMap.put("printType", "shumakuaiyin");
        List<GoodsCraftPriceEntity> kuaiyinGoodsCraftOptionPriceList = goodsCraftPriceService.getQuoteGoodsCraftOptionPriceList(parasMap);


        return R.ok().put("kuaiyinGoodsCraftOptionPriceList", kuaiyinGoodsCraftOptionPriceList);
    }

    /**
     * 保存快印商品工艺价格
     */
    @RequestMapping("/saveKuaiyin")
    @RequiresPermissions("goodsCraftPrice:goodscraftprice:save")
    public R saveKuaiyin(@Valid @RequestBody GoodsCraftPriceDto goodsCraftPriceDto){
        // 获取当前登录人
        String userName = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
        //商户id 此处自营写死
        Long sellerId = 1L;
        goodsCraftPriceService.saveKuaiyin(goodsCraftPriceDto.getCraftPriceList(), userName, sellerId);
        return R.ok();
    }





}
